﻿using System;
using System.Collections.Generic;
using NOSDC.Repositories.Jobs;
using NOSDC.Pocos;

namespace NOSDC.Services
{
    public sealed class JobService : IJobService
    {
        private readonly IJobRepository _repository;

        #region ctors
        public JobService(IJobRepository repository)
        {
            if (repository == null)
                throw new ArgumentException("You must provide a repository");

            _repository = repository;
        }

        public JobService() : this(new JobRepository()) { }


        #endregion

        public void PostJob(Job job)
        {
            job.DatePosted = DateTime.Now;
            _repository.PostJob(job);
        }

        public IEnumerable<Job> GetActiveJobs(bool includeActiveAtBottom = false)
        {
            return _repository.GetActiveJobs(includeActiveAtBottom);
        }

        public void UpdateJob(Job job)
        {
            _repository.UpdateJob(job);
        }

        public void DeleteJob(int id)
        {
            var job = _repository.GetJobById(id);

            if (job != null)
            {
                _repository.DeleteJob(job);
            }
        }

        public Job GetJobById(int id)
        {
            return _repository.GetJobById(id);
        }

        public IEnumerable<Job> GetRecentJobs()
        {
            return _repository.GetRecentJobs();
        }
    }
}
